package com.ttx.springmvc.example2.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 * @author TimFruit
 * @date 19-7-16 下午11:59
 */
@Api(value = "/home", tags="index模块")

@Controller
@RequestMapping("/home")
public class IndexController {

    @ApiOperation(value = "/index", notes = "index页面测试")
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index() {
        return "index";
    }





    @ApiOperation(value = "/request", notes = "requestBody")
    @PostMapping("/request")
    @ResponseBody
    public String requestBody(
            @RequestBody  String requestBody,
//                              @RequestHeader("Content-Type") String contentType,
                              HttpServletRequest request) throws IOException {
        System.out.println("requestBody: "+requestBody);
//        System.out.println("contentType: "+contentType);


        System.out.println("contentType2: "+request.getHeader("Content-Type"));



        String requestBody1=StreamUtils.copyToString(request.getInputStream(), Charset.forName("utf-8"));

        return requestBody1;

//        return requestBody;
    }
}